package com.pz.account.controller;

import com.pz.account.service.CommAccountService;
import com.pz.art.domain.AssoMemberInitiation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/mobile/account")
@RestController
public class CommAccountController {


    private final CommAccountService commAccountService;

    public CommAccountController(CommAccountService commAccountService) {
        this.commAccountService = commAccountService;
    }

    /**
     * 营业执照上传
     */
    @Log(title = "营业执照上传", businessType = BusinessType.OTHER)
    @PostMapping("/profile")
    public AjaxResult profile(@RequestParam MultipartFile file) throws Exception
    {
        if (!file.isEmpty())
        {
            String profile = FileUploadUtils.upload(RuoYiConfig.getProfile(), file, MimeTypeUtils.IMAGE_EXTENSION);
            return AjaxResult.success(profile);
        }
        return AjaxResult.error("上传图片异常，请联系管理员");
    }

    /**
     * 申请入会
     */
    @Log(title = "申请入会", businessType = BusinessType.INSERT)
    @PostMapping("/association")
    public AjaxResult applyassociation(AssoMemberInitiation assoMemberInitiation)
    {
        commAccountService.inserterAssociation(assoMemberInitiation);
        return AjaxResult.success("申请成功，请等待审核通过");
    }
}
